const users = require('../../data-source/user')
const tokens = require('../../data-source/token')

module.exports = [
  // 登录
  {
    url: '/user/login',
    type: 'post',
    response: config => {
      const { username, password } = config.body
      const token = tokens[username]

      if (!token) {
        return {
          code: 60204,
          message: '角色信息无效'
        }
      }

      if (password !== '666666') {
        return {
          code: 60204,
          message: '账号或密码错误'
        }
      }

      return {
        code: '0',
        data: token
      }
    }
  },

  // 获取用户信息
  {
    url: '/user/info\.*',
    type: 'get',
    response: config => {
      const { token } = config.query
      const info = users[token]

      if (!info) {
        return {
          code: 50008,
          message: '验证失败，非法的token'
        }
      }

      return {
        code: '0',
        data: info
      }
    }
  },

  // 登出
  {
    url: '/user/logout',
    type: 'post',
    response: _ => {
      return {
        code: '0',
        data: 'success'
      }
    }
  }
]
